//
//  TJBigImageController.m
//  Teleport
//
//  Created by hc-101 on 2020/6/17.
//  Copyright © 2020 xtjun. All rights reserved.
//

#import "TJBigImageController.h"

@interface TJBigImageController ()<UIGestureRecognizerDelegate>


@property (strong, nonatomic) UIScrollView *mainView;
@property (weak, nonatomic) UIImageView *bigImageView;


@end

@implementation TJBigImageController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        self.modalPresentationStyle = UIModalPresentationCustom;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.navigationBar.alpha = 0;
    self.navigationBar.lineView.hidden = YES;
    [self.navigationBar backBarButtonWhiteColor];
    
    
    
    self.view.backgroundColor = UIColor.blackColor;
    
    UIView *maskView = [UIView tj_addToView:self.view];
    maskView.backgroundColor = [UIColor.tj_alertMaskColor colorWithAlphaComponent:0];
    maskView.frame = self.view.bounds;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didClickDismissButton)];
    [maskView addGestureRecognizer:tap];
    tap.delegate = self;
    
    self.mainView = [UIScrollView tj_addToView:self.view];
    self.mainView.showsHorizontalScrollIndicator = NO;
    
    if (@available(iOS 11.0, *)) {
        self.mainView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    
    
    UIImageView *bigImageView = [UIImageView tj_addToView:self.mainView];
    _bigImageView = bigImageView;
    self.bigImageView.image = _image;
    self.bigImageView.frame = CGRectFlatMake(0, 0, KScreenWidth, KScreenWidth * self.image.size.height / MAX(self.image.size.width , 0.001));
    if (bigImageView.frame.size.height > KScreenHeight) {
        self.bigImageView.frame = CGRectFlatMake(0, 0, KScreenWidth, KScreenWidth * self.image.size.height / MAX(self.image.size.width , 0.001));
    } else {
        self.bigImageView.center = self.view.center;
        
    }
    self.mainView.contentSize = CGSizeMake(KScreenWidth, self.bigImageView.frame.size.height);
    
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    
    self.mainView.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
    
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    
    if (_viewDidDisappearhBlock) {
        _viewDidDisappearhBlock();
    }
    
}

- (void)didClickDismissButton {
    
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

@end
